package castorss.src.rss;

import java.util.ArrayList;
import java.util.List;

import android.R.array;
import android.app.Activity;
import android.content.Context;
import android.widget.TextView;

import com.google.code.rome.android.repackaged.com.sun.syndication.feed.synd.SyndEntry;
import com.google.code.rome.android.repackaged.com.sun.syndication.feed.synd.SyndFeed;

/**
 * Handles interaction with the RSS feeds.
 */
public class RSSHandler extends Object
{
	private String url;
	private SyndFeed feed;
	private Activity context;
	private ArrayList<RSSUrl> rssUrl_list;
	
	/**
	 * Constructor.
	 */
	public RSSHandler(Activity context_)
	{
		super();
		context = context_;
		rssUrl_list = new ArrayList<RSSUrl>();
	}
	
	public ArrayList<RSSUrl> getRssUrl_list() 
	{
		return rssUrl_list;
	}

	public void setRssUrl_list(ArrayList<RSSUrl> rssUrlList) 
	{
		rssUrl_list = rssUrlList;
	}
	
	/**
	 * Retrieves data from the rss feeds
	 * @return An ArrayList of RSSUrl, with feeds inside
	 */
	public void handle()
	{
		for (int i = 0; i < rssUrl_list.size(); i++ )
	    {
	    	RssAtomFeedRetriever feedRetriever = new RssAtomFeedRetriever(context);
		    feed = feedRetriever.getMostRecentNews(rssUrl_list.get(i).getUrl());
	    	rssUrl_list.get(i).setSyndFeed(feed);
	    }
	}
}